// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/functions/lib/lambda_function_util.h>
#include <pollux/testing/vector/vector_test_base.h>

namespace kumo::pollux::functions {
namespace {

class LambdaFunctionUtilTest : public testing::Test,
                               public pollux::VectorBuilder {
 protected:
  static void SetUpTestCase() {
    memory::MemoryManager::testingSetInstance({});
  }
};

TEST_F(LambdaFunctionUtilTest, addNullsForUnselectedRows) {
  auto vector = make_flat_vector<int64_t>({1, 2, 3, 4, 5});

  SelectivityVector rows(3);
  auto nulls = addNullsForUnselectedRows(vector, rows);

  auto* rawNulls = nulls->as<uint64_t>();

  EXPECT_FALSE(bits::isBitNull(rawNulls, 0));
  EXPECT_FALSE(bits::isBitNull(rawNulls, 1));
  EXPECT_FALSE(bits::isBitNull(rawNulls, 2));
  EXPECT_TRUE(bits::isBitNull(rawNulls, 3));
  EXPECT_TRUE(bits::isBitNull(rawNulls, 4));
}

} // namespace
} // namespace kumo::pollux::functions
